﻿/******************************************************************
** auth: wei.huazhong
** date: 8/17/2020 11:49:13
** desc:
******************************************************************/

using System;
using System.Collections.Generic;
using static System.String;
using System.Text;
using Models;
using Microsoft.Extensions.Options;
using System.Linq;

namespace DAL
{
    public class MockDAL
    {
        private MockData _mockdata;
        public MockDAL(IOptions<MockData> mockdata)
        {
            _mockdata = mockdata.Value;
        }

        public User GetUserByID(int userId)
        {
            return _mockdata.Users.FirstOrDefault(m => m.ID == userId);
        }

        public User GetUserByName(string name)
        {
            return _mockdata.Users.FirstOrDefault(m => m.Name.Trim() == name.Trim());
        }
        public IEnumerable<Role> GetRolesByUserID(int userID)
        {
            var query = from roles in _mockdata.Roles
                        join userRole in _mockdata.UserRoleMappings on roles.ID equals userRole.RoleID
                        where userRole.UserID == userID
                        select roles;

            return query.ToList();
        }
    }
}
